import logging
import time
import os
from Base.basePath import BasePath as BP
from Base.utils import read_config_ini

config = read_config_ini(BP.CONFIG_FILE)['日志打印配置']
rq = time.strftime('%Y%m%d_%H', time.localtime()) + '.log'


class Logger(object):

    def __init__(self, name):
        self.name = name
        self.logger = logging.getLogger(self.name)
        self.logger.setLevel(config['level'])
        self.streamHandler = logging.StreamHandler()
        self.fileHandler = logging.FileHandler(os.path.join(BP.PROJECT_ROOT, "Log",rq), 'a',encoding='utf-8')
        self.formatter = logging.Formatter(config['formatter'])
        self.streamHandler.setLevel(config['stream_handler_level'])
        self.fileHandler.setLevel(config['file_handler_level'])
        self.fileHandler.setFormatter(self.formatter)
        self.streamHandler.setFormatter(self.formatter)
        self.logger.addHandler(self.streamHandler)
        self.logger.addHandler(self.fileHandler)

    def getLogger(self):
        return self.logger

if __name__ == "__main__":
    logger= Logger('baseLogger.py').getLogger()
    print(logger)
    print(config)
    print(rq)
    logger.info("info级别的信息")